#include<bits/stdc++.h>
#define int long long
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define For(i,a,b) for(int i=a;i<=b;++i)
#define Rof(i,a,b) for(int i=a;i>=b;--i)
#define rep(i,a) for(int i=1;i<=a;++i)
#define print(x) printf("%lld\n",(int)x)
#define prn(x) printf("%lld ",(int)x)
using namespace std;
const int N=1e6+5,Mod=998244353;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){f=(ch=='-'?-f:f);ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*f;
}
int n,a[N];
int m;
int l[N],r[N];
struct XXX{
	int l,r;
}z[N];
inline bool cmp(XXX a,XXX b){
	return a.l<b.l;
}
int tr[N<<2],lz[N<<2];
void build(int x,int l,int r){
	tr[x]=lz[x]=1e16;
	if(l==r) return;
	int mid=(l+r)>>1;
	build(ls(x),l,mid);
	build(rs(x),mid+1,r);
}
inline void down(int x,int k){
	tr[x]=min(tr[x],k);
	lz[x]=min(lz[x],k);
}
inline void pushdown(int x){
	down(ls(x),lz[x]);
	down(rs(x),lz[x]);
	lz[x]=1e16;
}
inline void pushup(int x){tr[x]=min(tr[ls(x)],tr[rs(x)]);}
void updata(int x,int l,int r,int L,int R,int k){
	if(L<=l&&r<=R){
		down(x,k);
		return;	
	}
	int mid=(l+r)>>1;pushdown(x);
	if(L<=mid) updata(ls(x),l,mid,L,R,k);
	if(R>mid)updata(rs(x),mid+1,r,L,R,k);
	pushup(x);
}
int query(int x,int l,int r,int k){
	if(l==r) return tr[x];
	int mid=(l+r)>>1;pushdown(x);
	if(k<=mid)  return query(ls(x),l,mid,k);
	else return query(rs(x),mid+1,r,k);
}
signed main(){
	freopen("gonna.in","r",stdin);
	freopen("gonna.out","w",stdout);
	n=read();
	For(i,1,n)a[i]=read();
	m=read();
	For(i,1,m){
		z[i].l=read(),z[i].r=read();
	}	
	sort(z+1,z+m+1,cmp);
	int t=m,mx=n+1;
	Rof(i,n,1){
		r[i]=mx;
		//~ cout<<mx<<" ";
		while(z[t].l==i) mx=min(mx,z[t].r),t--;
	}build(1,1,n+1);
	updata(1,1,n+1,1,mx,0);
	For(i,1,n){
		int x=query(1,1,n+1,i)+a[i];
		updata(1,1,n+1,i+1,r[i],x);
		//~ cout<<x<<" ";
	}printf("%lld\n",query(1,1,n+1,n+1));
	return 0;
}
//
